package com.zhanghe.study.springboot.configuration;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

/**
 * @author zh
 * @date 2021/3/18 16:06
 */
public class JwtConfig {

    private String secret;
    private long expire;
    private String header;

    public static String generateToken(){
//        Date date = new Date();

        return Jwts.builder().setHeaderParam("typ","jwt")
//                .setHeaderParam("alg","HS256")
                .setPayload("{\"name\":\"123\"}")
                .signWith(SignatureAlgorithm.HS512,"bvvbvjkvnwovb").compact();
    }

    public static Claims getClaimsByToken(String token){
        return Jwts.parser().setSigningKey("bvvbvjkvnwovb")
                .parseClaimsJws(token)
                .getBody();
    }

    public static void main(String[] args) {
        String token = generateToken();
        System.out.println(token);
        Claims claims = getClaimsByToken(token);
        System.out.println(claims.toString());
    }
}
